package com.deyuanyun.pic.pipe.support.validatefun;

import com.caixu.beanvalidateutil.vinterface.ValidateInterface;
import com.deyuanyun.pic.common.util.ObjectUtil;
import com.deyuanyun.pic.pipe.support.utils.PipeDictUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.StringUtils;

import java.lang.reflect.Field;

public class ValveRoomValidata implements ValidateInterface {

	@Override
	public <T, E,C> boolean apply(T t, E e,C c) {
		if(ObjectUtil.isNotNullEmpty(t)){
			Field f=(Field) e;//管段
			String roomId= PipeDictUtils.getRoomIByName(((String) t).trim());
			if(StringUtils.isNotBlank(roomId))
			{
				try {
					BeanUtils.setProperty(c,f.getName(),roomId);
				} catch (Exception e1) {
					e1.printStackTrace();
					return false;
				}
				return true;
			}
			return false;
		}
		return true;
	}

	@Override
	public String getName() {
		return null;
	}

}
